<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        padding: 0;
        margin: 0;
    }

    .baidu li {
        list-style: none;
    }

    .baidu img {
        width: 400px;
        height: 300px;
    }

    .text {
        display: flex;
        font-size: 24px;
        font-weight: 700;
        letter-spacing: 20px;
        justify-content: center;
        list-style: none;
        margin-top: 50px;
    }
</style>

<body>
    <ul class="text">
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
    </ul>
    <ul class="baidu">
        <img src="images/1.jpg" alt="">
        <img src="images/2.jpg" alt="">
        <img src="images/3.jpg" alt="">
        <img src="images/4.jpg" alt="">
    </ul>
</body>
<script>
    let lis = document.getElementsByTagName('li');
    let imgs = document.getElementsByTagName('img');
    // console.log(imgs);
    
    // 1. 拿到1234的数据 那么就要循环啦 循环的去点击
    for(let i =0;i<lis.length;i++){
        // console.log(i);  //一共四个 拿到4个 小于lis.length
        lis[i].index = i; // 把i 的 0 1 2 3赋值给当前点击的index索引 之后的imgs[this.index]才起作用
        // console.log(i);
        lis[i].onmouseover = function(){
            this.style.background = 'pink';  //这里设置之后每个li都会变成粉色
            // 3. 也要有对应的背景 让背景的索引号和文字一样
            for(let j = 0;j <imgs.length;j++){
               imgs[j].style.display = 'none';
            }
            imgs[this.index].style.display = 'block';
            console.log(imgs[this.index]);  // 这里就是拿到图片 以及对饮的索引
        }
        // 2.
        lis[i].onmouseout = function(){
            this.style.background = '';  //鼠标离开之后 没有背景颜色
        }
    }
</script>

</html>